#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QtWidgets>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("Wallpaper" + QString("(主屏分辨率:%1,%2 %3x%4)")
                   .arg(PrimaryScreenGeometry.x())
                   .arg(PrimaryScreenGeometry.y())
                   .arg(PrimaryScreenGeometry.width())
                   .arg(PrimaryScreenGeometry.height()));
    ui->label_infolist->setAlignment(Qt::AlignVCenter | Qt::AlignRight);

    ui->widget->setFixedSize(PrimaryScreenGeometry.size() * 0.5);
    QTimer::singleShot(100, this, [&](){
        ui->widget->setPixmap(QImage("C:/Users/ch593/Desktop/陆雪琪/2024-10-07/陆雪琪 (38).png"));
        ui->listWidget->setDir("C:/Users/ch593/Desktop/陆雪琪/过滤");
    });
    connect(ui->listWidget, &QListWidget::itemClicked, this, [&](QListWidgetItem *item){
        ui->widget->setPixmap(QImage(item->data(Qt::UserRole).toString()));
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::updateListInfo(const QString &message)
{
    ui->label_infolist->setText(message);
}

void MainWindow::updateViewInfo(const QString &message)
{
    ui->label_infoview->setText(message);
}

void MainWindow::on_pushButton_clicked()
{
    ui->widget->save();
}


void MainWindow::on_pushButton_2_clicked()
{
    QString path = QFileDialog::getExistingDirectory(this, "get directory", "C:/Users/ch593/Desktop/陆雪琪");
    if(path.isEmpty())
        return;
    ui->listWidget->setDir(path);
}


void MainWindow::on_pushButton_flipvertical_clicked()
{
    ui->widget->flipvertical();
}
